home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
DEMO_CMN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-21
|
7KB
|
178 lines
program DEMO_CMN;
{------------------------------------------------------------------------------
Griffin Solutions String and Date Features
Demo Program
Copyright (c) Richard F. Griffin
10 February 1992
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This program demonstrates how string and date values may be
accessed using Griffin Solutions units.
------
Date field operations are performed in the GS_DATE.PAS unit.
This provides a longint julian date, a string in MM/DD/YY
format, and a dBase Date field format YYYYMMDD.
An astronomers' Julian day number is a calendar system which is
useful over a very large span of time. (January 1, 1988 A.D. is
2,447,162 in this system.) The valid range of dates allowed is
March 1, 0000 through December 31, 65535.
By assigning a longint julian date, computing differences between
dates, adding days to an existing date, and other mathematical
actions become much easier.
A GS_Date_Century flag may be set. When true, the GS_Date_View
function will return MM/DD/YYYY. When false, only the last two
digits of the year will be returned (MM/DD/YY). The default is false.
------
The following string-handling routines are available in GS_STRNG.PAS:
function AllCaps(var t : string) : string;
Sets string to upper case.
procedure CnvAscToStr(var asc, st; lth : integer);
Copies ZASCII field to a string
procedure CnvStrToAsc(var st, asc; lth : integer);
Copies string to a ZASCII field
function StrDate(jul : longint) : string;
Converts a julian date to a string
in MM/DD/YY (or MM/DD/YYYY) format.
function StrNumber(num : real; lth,dec : integer) : string;
Converts a real number to a string
function StrLogic(tf : boolean) : string;
Converts a boolean value to a string
value of 'T' or 'F'
function Strip_Flip(st : string) : string;
Removes trailing spaces and moves any
part of the string that is preceeded
by a '~' to the end of the string.
For Example:
Smith~John X.
will be converted to:
John X. Smith
function SubStr(s : string; b,l : integer) : string;
Returns a substring of the string s
function TrimL(strn : string):string;
Deletes leading spaces
function TrimR(strn : string):string;
Deletes trailing spaces
function Unique_Field : string;
Used to create a unique 8-byte string
First character is alpha and others
are alpha(uppercase) or numeric.
function ValDate(strn : string) : longint;
Converts a date string of either
MM/DD/YY or YYYYMMDD to the longint
julian day.
function ValNumber(strn : string) : real;
Converts a string to a real number.
Returns 0 for invalid string;
function ValLogic(strn : string) : boolean;
Creates a boolean value based on the
string. If strn[1] is Y,y,T, or t
then it will return true; otherwise
it will return false.
-------------------------------------------------------------------------------}
{$V-}
uses
CRT,
GS_Date,
GS_Strng;
var
RealValue : real;
LogicValue : boolean;
DateValue : longint;
LogicString,
RealString,
Str1String,
Str2String,
UniqString,
DateString : string[20];
ZASCII : array[0..20] of char;
i : integer;
begin
ClrScr;
Str1String := ' Smith~John ';
writeln('Original input -->':30,Str1String,'<--');
writeln('UpperCase -->':30,AllCaps(Str1String),'<--');
CnvStrToAsc(Str1String, ZASCII, sizeof(ZASCII));
write('ZASCII String -->':30);
i := 0;
while ZASCII[i] <> #0 do
begin
write(ZASCII[i]);
inc(i);
end;
writeln('<--');
CnvAscToStr(ZASCII, Str2String, i);
writeln('Pascal String from ZASCII -->':30,Str2String,'<--');
Str1String := TrimL(Str1String);
writeln('Trim Leading Spaces -->':30,Str1String,'<--');
Str1String := TrimR(Str1String);
writeln('Trim Trailing Spaces -->':30,Str1String,'<--');
writeln('Substring Chars 3-8 -->':30,SubStr(Str1String,3,6),'<--');
writeln('Flip String at ~ -->':30,Strip_Flip(Str1String),'<--');
writeln('Get Unique Field -->':30,Unique_Field,'<--');
DateString := '02/28/1992';
DateValue := ValDate(DateString);
writeln('Julian Date for 02/28/1992 -->':30,DateValue,'<--');
GS_Date_Century := false;
writeln('Date+90 Days (Century Off) -->':30,StrDate(DateValue+90),'<--');
GS_Date_Century := true;
writeln('Date+90 Days (Century On) -->':30,StrDate(DateValue+90),'<--');
RealValue := 123.456;
writeln('Value 123.456 w/ $ edit -->':30,'$',StrNumber(RealValue,6,2),'<--');
RealString := StrNumber(RealValue + 78.9,9,4);
writeln('String of 123.456 + 78.9 -->':30,RealString,'<--');
writeln('Real of String/2 -->':30,ValNumber(RealString)/2,'<--');
writeln('Formatted String/2 -->':30,ValNumber(RealString)/2:7:4,'<--');
LogicValue := true;
LogicString := StrLogic(LogicValue);
writeln('Logic string for true -->':30,LogicString,'<--');
writeln('Logic boolean for true -->':30,ValLogic(LogicString),'<--');
write('Press any key to continue:');
repeat until KeyPressed;
end.